// typescript基础类型
import * as React from 'react';

declare function create(o: object | null): void;

class BaseType extends React.Component {

  public toSubTool = () => {
    const name = 'history';
    this.props[name].push('/subTool')
  }

  public init = () => {
      // boolean
      const isDone: boolean = false;
      // number
      const age: number = 6;
      // string
      const name: string = 'bob'
      const say: string = `${name} say hai`;
      // array
      const numberList: number[] = [1, 2, 3];
      const stringList: string[] = ['bob', 'alice'];
        // const animalList: Array<string> = ['cat', 'dog', 'pig']
      const animalList: string[] = ['cat', 'dog'];
      // Tuple
      let x: [string, number];
      x = ['hello', 10];
      x[0] = 'gggsak';
      console.log(x[0].substr(1));
      console.log(isDone, age, name, say, numberList, stringList, animalList, x);
  }

  public enumInit = () => {
    enum Color { Red = 2, Green = 2, Blue = 2 }
    const c: Color = Color.Green;
    const colorName: string = Color[2];
    console.log(c, colorName)
  }

  public anyInit = () => {
    let notSure: any = true
    notSure = 'maybe string instead'
    console.log(notSure)
    const list: any[] = [1, true, 'green']
    list[1] = '100'
    console.log(list)
  }

  public voidInit = (): void => {
    const unusable: void = undefined
    console.log(unusable)
  }

  public nullAndUndifined = () => {
    const n: null = null
    const u: undefined = undefined
    let str: string|null = null
    str = 'happy'
    console.log(n, u, str)
  }

  public objectInit = () => {
    const a: object = {a: 'kk'}
    console.log(a)
  }

  public typeJudge = () => {
    const someValue: any = 'string';
    const strLength1: number = (someValue as string).length;
    console.log(strLength1)
  }

  public componentDidMount(){
      // this.init()
    // this.enumInit()
    // this.anyInit()
    // this.voidInit()
    // this.nullAndUndifined()
    // this.objectInit()
    this.typeJudge()
  }
  public render() {
    return (
      <div>
        BaseType
        <button onClick={this.toSubTool}>to subTool</button>
      </div>
    );
  }
}

export default BaseType;
